package com.project.poetry.service.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.project.poetry.service.entity.dto.job.JobDTO;
import com.project.poetry.service.entity.po.job.JobPO;
import com.project.poetry.service.service.JobService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

/**
 * 任务控制器
 * @author mengxj
 */
@Api("任务")
@RestController
@RequestMapping("job")
@Validated
public class JobController {

    @Resource
    private JobService jobService;

    @ApiOperation("创建任务")
    @PostMapping("saveJob")
    public void saveJob(@RequestBody @Valid JobPO job){
        this.jobService.saveJob(job);
    }

    @ApiOperation("修改任务")
    @PutMapping("updateJob")
    public void updateJob(@RequestBody @Valid JobPO job){
        this.jobService.updateJob(job);
    }

    @ApiOperation("暂停任务")
    @GetMapping("pauseJob")
    public void pauseJob(@RequestParam("jobId") Long jobId){
        this.jobService.pauseJob(jobId);
    }

    @ApiOperation("恢复任务")
    @GetMapping("resumeJob")
    public void resumeJob(@RequestParam("jobId") Long jobId){
        this.jobService.resumeJob(jobId);
    }

    @ApiOperation("删除任务")
    @DeleteMapping("deleteJob")
    public void deleteJob(@RequestParam("jobId") Long jobId){
        this.jobService.deleteJob(jobId);
    }

    @ApiOperation("直接启动任务")
    @GetMapping("run")
    public void run(@RequestParam("jobId") Long jobId){
        this.jobService.run(jobId);
    }

    @ApiOperation("查询job列表")
    @PostMapping("list")
    public IPage<JobPO> list(@RequestBody JobDTO job){
        return this.jobService.list(job);
    }
}
